import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:xuance/bean/HomeInfo.dart';
import 'package:xuance/page/main/ban_list/view.dart';
import 'package:xuance/page/main/home/view.dart';
import 'package:xuance/page/main/me/me_view.dart';
import 'package:xuance/page/main/rule_warn/view.dart';
import 'package:xuance/services/FloatingPanelService.dart';

import 'state.dart';

class MainLogic extends GetxController {
  final MainState state = MainState();
  final pageController = PageController();

  @override
  void onInit() {
    super.onInit();
    Get.put(FloatingPanelService());
    state.pages.addAll([
      HomeInfo(
          title: "模型预警",
          page: const HomePage(),
          bottom: const BottomNavigationBarItem(
              tooltip: "模型预警",
              label: "模型预警",
              icon: Icon(Icons.table_chart_rounded),
              activeIcon: Icon(Icons.table_chart_rounded))),
      HomeInfo(
          title: "规则预警",
          page: const RuleWarnPage(),
          bottom: const BottomNavigationBarItem(
              tooltip: "规则预警",
              label: "规则预警",
              icon: Icon(Icons.bookmark_remove_sharp),
              activeIcon: Icon(Icons.bookmark_remove_sharp))),
      HomeInfo(
          title: "封禁列表",
          page: const BanListPage(),
          bottom: const BottomNavigationBarItem(
              tooltip: "封禁列表",
              label: "封禁列表",
              icon: Icon(Icons.view_list),
              activeIcon: Icon(Icons.view_list))),
      HomeInfo(
          title: "账户管理",
          page: const MePage(),
          bottom: const BottomNavigationBarItem(
              tooltip: "账户管理",
              label: "账户管理",
              icon: Icon(Icons.accessible_forward_outlined),
              activeIcon: Icon(Icons.accessible_forward_outlined))),
    ]);
  }

  void changePage(int index, bool byBottom) async {
    if (byBottom) {
      pageController.animateToPage(index,
          duration: const Duration(milliseconds: 200), curve: Curves.linear);
    }
    state.currentIndex.value = index;
  }
}
